export default {
	state: {
		list: []
	},
	mutations: {
		addPurchase(state, goods) {
			state.list.splice(0);
			if (Array.isArray(goods)) {
				state.list = [...goods];
			} else {
				state.list.push(goods);
			}
		},
		clearPurchase(state) {
			state.list.splice(0)
		}
	},
	actions: {
		addPurchase({commit}, goods) {
			commit('addPurchase', goods);
		},
		clearPurchase({commit}) {
			commit('clearPurchase');
		}
	},
	getters: {
		purchaseTotal(state) {
			let total = 0;
			for (let item of state.list) {
				total += item.count * item.price;
			}
			return total;
		}
	}
}
